(() => {
  let ele = {};
  ele.bot_list = $("#bot_list");
  ele.more = $("#more");
  ele.empty = $("#empty");
  let list = [];
  let page = 1;
  // !发送请求
  asyncList();
  function asyncList() {
    let token = getCookie("token");
    ajax({
      method: "get",
      url: API_PATH.MYJILU,
      header: {
        Authorization: token,
      },
      data: {
        page: page,
        // size: 2,
      },
      success: (res) => {
        if (res.code == 1) {
          list = [...list, ...res.data.record.data];
          if (list.length === 0) {
            page = 0;
            ele.more.style.display = "none";
            ele.empty.style.display = "block";
          } else {
            initList();
            page++;
            if (page > res.data.record.last_page) {
              ele.more.innerText = "没有更多了";
              ele.more.onclick = null;
            } else {
              ele.more.innerText = "加载更多";
              ele.more.onclick = () => asyncList(page);
            }
          }
        } else openTips(res.msg);
        initList();
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // !渲染数据
  function initList() {
    let newList = list
      .map((item) => {
        return `
      <div class="list_son">
      <div class="left">
        <div class="img">
          <img src="${IMG_DOMAIN + item.house_detail.logo}" alt="" />
        </div>
        <div class="cen">
          <p class="t">${item.house_detail.name}</p>
          <p class="z">房产编号：${item.no}</p>
          <p style="display:${
            item.type == 1 ? "block" : "none"
          };" class="h">类型：房产出售</p>
          <p style="display:${
            item.type == 2 ? "block" : "none"
          };" class="h">类型：房产拍卖</p>
          <p style="display:${
            item.type == 3 ? "block" : "none"
          };" class="h">类型：违约拍卖</p>
        </div>
      </div>
      <div class="left_btn">
        <div class="c">成交价格：${item.over_money}金币</div>
    <div class="c">获得玩家：${
      item.to_agent && item.to_agent.nick_name
        ? item.to_agent.nick_name
        : "天天收租"
    }</div>
    <div class="c">状态：${item.state == 10 ? "交易完成" : "取消交易"}</div>
        <div class="c">日期:${item.created_at.split(" ")[0]}</div>
      </div>
    </div>`;
      })
      .join(" ");
    ele.bot_list.innerHTML = newList;
  }
})();
